package login.controller;

import commons.pojo.Users;
import commons.vo.LivegoodsResult;
import login.dao.LoginMapper;
import login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/setUser")
    public LivegoodsResult setUser(@RequestBody Users users){
        String username = users.getName();
        String password = users.getPassword();
        LivegoodsResult livegoodsResult = loginService.setUser(username, password);
        return livegoodsResult;
    }

//    @GetMapping("/user")
//    public int user(){
//        UserDetails currentUserDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        System.out.println(currentUserDetails);
//        return 1;
//    }
    @PostMapping ("/loginU")
    public LivegoodsResult loginUser(@RequestBody Users users){
        String username = users.getName();
        String password = users.getPassword();
        return loginService.loginUser(username, password);
    }
}